import java.sql.*;

import static java.sql.DriverManager.getConnection;

public class Main {
    public static void main(String[] args) throws SQLException {
        PreparedStatement stmt = null;
        Connection connection=null;
        try {
            String url = "jdbc:mysql://localhost:3306/library?useSSL=false";
            String user="root";
            String password = "root";

            //1. 注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2. 获取连接
            connection= getConnection(url,user,password);
            System.out.println(connection);

            stmt = connection.prepareStatement("insert into soft_bookrack (book_name, book_author, book_isbn) values (?,?,?);");

            stmt.setString(1, "我是第一个参数");
            stmt.setString(2, "宋浩");
            stmt.setString(3, "1450792379");

            //执行
            stmt.execute();
            //回收资源

        } catch (ClassNotFoundException | SQLException e) {
            throw new RuntimeException(e);
        } finally {
            stmt.close();
            connection.close();
        }



    }
}